package com.cxf.windex.rest.admin;

import com.cxf.windex.base.constant.UserConstant;
import com.cxf.windex.base.msg.ObjectRestResponse;
import com.cxf.windex.base.msg.TableResultResponse;
import com.cxf.windex.base.rest.BaseRestController;
import com.cxf.windex.biz.BResourcesBiz;
import com.cxf.windex.entity.BResouces;
import com.cxf.windex.entity.BShop;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: business_needs
 * @description: 资源管理
 * @author: chenxf
 * @create: 2018-11-06 10:03
 **/
@Api(tags = {"村广通[后台] - 资源方管理"})
@Controller
@RequestMapping("admin/resources")
public class AdminResourceController  extends BaseRestController<BResourcesBiz,BResouces> {
  @ApiOperation(value = "查询资源", notes = "查询资源列表")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "limit", value = "记录数 默认10", required = false, paramType = "query", dataType = "int"),
      @ApiImplicitParam(name = "offset", value = "页码 默认 1", required = false, paramType = "query", dataType = "int"),
      @ApiImplicitParam(name = "orderStr", value = "排序 默认desc", required = false, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "provice", value = "省", required = false, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "city", value = "市", required = false, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "county", value = "区县", required = false, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "status", value = "状态 0待审核 1审核通过 2审核未通过", required = false, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "name", value = "类型名称", required = false, paramType = "query", dataType = "String"),
  })
  @RequestMapping(value = "/list", method = RequestMethod.GET)
  @ResponseBody
  public TableResultResponse<BResouces> list(
      @RequestParam(defaultValue = "10") int limit, @RequestParam(defaultValue = "1") int offset,
      @RequestParam(defaultValue = "desc") String orderStr,  String name,String provice,String city,String county,String status) {
    List<BResouces> items = baseBiz.list(limit, offset, orderStr,  name, provice, city, county,status,"");
    PageInfo<BResouces> pageInfo = new PageInfo<>(items);
    return new TableResultResponse<BResouces>(Integer.parseInt(String.valueOf(pageInfo.getTotal())),
        offset, limit,
        items);
  }

  @ApiOperation(value = "查询有效资源", notes = "查询有效村长资源")
  @ApiImplicitParams({
     @ApiImplicitParam(name = "name", value = "类型名称",  paramType = "query", dataType = "String"),
  })
  @RequestMapping(value = "/adminList", method = RequestMethod.GET)
  @ResponseBody
  public ObjectRestResponse<BResouces> adminList( String name) {
    return ObjectRestResponse.success("查询成功").result(baseBiz.adminList( name));
  }
  @ApiOperation(value = "根据ID获取福蛙信息", notes = "根据ID获取福蛙信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "id", value = "福蛙ID", required = true, paramType = "query", dataType = "long")
  })
  @RequestMapping(value = "/getInfo", method = RequestMethod.GET)
  @ResponseBody
  public ObjectRestResponse getInfo(Long id){
    BResouces entity=baseBiz.selectById(id);
    if(entity==null){
      return new ObjectRestResponse("找不到相关信息").rel(false);
    }
    return new ObjectRestResponse("查询成功").rel(true).result(entity);
  }

  @ApiOperation(value = "保存审核福蛙信息", notes = "保存审核福蛙结果信息")
  @RequestMapping(value = "/save", method = RequestMethod.POST)
  @ResponseBody
  public ObjectRestResponse save(BResouces entity){
    baseBiz.save(entity);
    return new ObjectRestResponse("保存成功").rel(true);
  }
}
